package com.abso.sunlight.api;

import org.apache.commons.lang.StringUtils;

/** Legislator's gender. */
public enum Gender {

    MALE, FEMALE, UNKNOWN;

    /**
     * Gets the gender's abbreviation (M or F).
     * 
     * @return the gender's abbreviation.
     */
    public String getAbbreviation() {
        return name().substring(0, 1);
    }

    /**
     * Gets the enum constant with the specified abbreviation.
     * 
     * @param abbr
     *            the gender's abbreviation (M or F).
     * @return the enum constant with the specified abbreviation.
     * @throws SunlightException
     *             if the abbreviation is invalid.
     */
    public static Gender valueOfAbbreviation(String abbr) {
        if ("F".equals(abbr)) {
            return FEMALE;
        } else if ("M".equals(abbr)) {
            return MALE;
        } else {
            return UNKNOWN;
        }
    }

    @Override
    public String toString() {
        return StringUtils.capitalize(this.name().toLowerCase());
    }

}
